<template>
    <!-- 添加或修改产品碳足迹对话框 -->
    <el-dialog title="减排路径" :visible.sync="open" width="800px" append-to-body :close-on-click-modal="false" custom-class="dialogPadDiv">
      <el-table :data="tableData"  border height="450px"  highlight-current-row
                @current-change="handleCurrentChange">
        <el-table-column label="" align="center"  width="35">
          <template slot-scope="scope">
            <el-radio v-model="currentRowId" :label="scope.row.id"></el-radio>
          </template>
        </el-table-column>
        <el-table-column label="序号" align="center" type="index" width="50" />
        <el-table-column label="名称" align="center" prop="name" :show-overflow-tooltip="true"/>
        <el-table-column label="所属企业" align="center" prop="enterpriseId"  :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{selectDictLabel($store.state.factorDict.enterpriseOptions, scope.row.enterpriseId,'id','enterpriseName')}}
          </template>
        </el-table-column>
            <el-table-column label="一级分类" align="center" prop="categorizeCode"   :show-overflow-tooltip="true">
              <template slot-scope="scope">
               <span v-if="scope.row.categorizeCode">
                 {{selectDictLabel($store.state.factorDict.categorizeInfoOptions, scope.row.categorizeCode.split(",")[0],'id','chineseName')}}
               </span>
              </template>
            </el-table-column>
        <el-table-column label="产品批次" align="center" prop="productBatch"  :show-overflow-tooltip="true"/>
        <el-table-column label="排放因子值" align="center" prop="factorNum"  :show-overflow-tooltip="true"/>
      </el-table>

      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">采 纳</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
</template>

<script>
import {selectEmissionPathList,summaryCarbonConsumablesLog} from "@/api/carbon/productCarbonConsumables";
export default {
  name: "ProductCarbonForm",
  data() {
    return {
      open: false,
      ids: [],
      tableData:[],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        id: null,
      },
      total: 0,
      currentRowId: null,
    };
  },
  created() {
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
    },
    handleCurrentChange(val) {
      this.currentRowId = val.id;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.ids=[];
      this.tableData=[];
    },
    /** 修改按钮操作 */
    handleShow(row) {
      this.queryParams.id=row.id;
      this.getList();
    },
    getList() {
      selectEmissionPathList(this.queryParams).then(res=>{
        this.open = true;
        this.tableData=res.rows;
        this.total = res.total;
      })
    },
    /** 提交按钮 */
    submitForm() {
      if(this.currentRowId==null){
        this.msgError("请选择排放因子");
        return
      }
      let data = {id: this.queryParams.id,stageIds:[this.currentRowId]};
      summaryCarbonConsumablesLog(data).then(response => {
          if (response.code === '200') {
              this.msgSuccess("汇总成功");
              this.open = false;
          }
      });
    },

  }
};
</script>
